using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using eShop.Business;
using eShop.Business;
using eShop.Model.MetaData;
using System.Collections.Generic;

public partial class admin_settings : SiteAdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        uccResponseMessage.Visible = false;
        if (!Page.IsPostBack)
        {
            BindData();
        }

    }

    protected void BindData()
    {
        List<Country> countries = MetaDataManager.GetAllCountries();
        ddlCompanyCountry.DataSource = countries;
        ddlCompanyCountry.DataTextField = "Name";
        ddlCompanyCountry.DataValueField = "Id";
        ddlCompanyCountry.DataBind();

        tbxCompanyName.Text = SiteSettings.CompanyName;
        tbxCompanyAddress.Text = SiteSettings.CompanyAddress;
        tbxCompanyZip.Text = SiteSettings.CompanyZip;
        tbxCompanyCity.Text = SiteSettings.CompanyCity;
        ListItem CompanyCountry = ddlCompanyCountry.Items.FindByText(SiteSettings.CompanyCountry);
        if (CompanyCountry != null)
            CompanyCountry.Selected = true;

        tbxCompanyPhone.Text = SiteSettings.CompanyPhone;
        tbxCompanyFax.Text = SiteSettings.CompanyFax;
        tbxCustomerPrefix.Text = SiteSettings.CustomerPrefix;
        tbxOderPrefix.Text = SiteSettings.OrderPrefix;
        tbxAdminEmail.Text = SiteSettings.AdminEmail;
        tbxStockAlertLevel.Text = SiteSettings.StockAlertLevel.ToString();
        tbxFreeGroundShipping.Text = SiteSettings.GroundShippingAmount.ToString();
        chkIsfreeGround.Checked = SiteSettings.IsGroundShippingFree;

        //LoadProductDropDownList();
        //BindFavoriteGrid();
    }

    protected void Create_Click(object sender, EventArgs e)
    {
        try
        {
            SiteSettings.CompanyName = tbxCompanyName.Text;
            SiteSettings.CompanyAddress = tbxCompanyAddress.Text;
            SiteSettings.CompanyZip = tbxCompanyZip.Text;
            SiteSettings.CompanyCity = tbxCompanyCity.Text;
            SiteSettings.CompanyCountry = ddlCompanyCountry.SelectedItem.Text;
            SiteSettings.CompanyPhone = tbxCompanyPhone.Text;
            SiteSettings.CompanyFax = tbxCompanyFax.Text;
            SiteSettings.CustomerPrefix = tbxCustomerPrefix.Text;
            SiteSettings.OrderPrefix = tbxOderPrefix.Text;
            SiteSettings.AdminEmail = tbxAdminEmail.Text;
            SiteSettings.GroundShippingAmount = Convert.ToDouble(tbxFreeGroundShipping.Text.ToString());
            SiteSettings.IsGroundShippingFree = chkIsfreeGround.Checked;
            int stockAlertLevel;
            int.TryParse(tbxStockAlertLevel.Text, out stockAlertLevel);
            SiteSettings.StockAlertLevel = stockAlertLevel;
            SiteSettings.Save();
            uccResponseMessage.SetSuccessMessage(ApplicationMessage.SaveSucceed);
            uccResponseMessage.Visible = true;
        }
        catch (Exception ex)
        {
            uccResponseMessage.SetFailMessage(ApplicationMessage.SaveProblem);
            uccResponseMessage.Visible = true;
        }
    }
}
